import request from '@/config/axios'

export interface ProfileVO {
  staffId: string
  loginName: string
  nickname: string
  email: string
  mobile: string
  gender: number
  avatar?: string
  loginIp?: string
  loginTime?: string
  createTime?: string
  roles: {
    id: number
    name: string
    status: number
  }[]
  dept: {
    id: number
    name: string
    status: number
  }
  posts: {
    id: number
    name: string
    status: number
  }[]
  socialUsers: {
    type: number
    openid: string
  }[]
}

export interface UserProfileUpdateVO {
  nickname: string
  email: string
  mobile: string
  gender: number
}

export const getUserProfile = async () => {
  return await request.get({ url: '/system/user/profile/get' })
}

export const updateUserProfile = async (data: UserProfileUpdateVO) => {
  return await request.post({ url: '/system/user/profile/update', data })
}

export const updateUserPassword = async (oldPassword: string, newPassword: string) => {
  return await request.post({
    url: '/system/user/profile/update-password',
    data: {
      oldPassword: oldPassword,
      newPassword: newPassword
    }
  })
}

export const updateUserAvatar = async (avatar: string) => {
  return await request.post({ url: '/system/user/profile/update-avatar', data: { avatar: avatar } })
}
